package com.pet.client.common;

import java.io.File;
import java.util.Date;

import com.pet.framework.page.ATTPage;
import com.pet.framework.page.Page;
import com.pet.framework.page.PagerFactory;
import com.pet.framework.util.BaseAction;
import com.pet.server.bo.common.ProductService;
import com.pet.server.http.bean.ProductImg;
import com.pet.server.po.ProductData;
import com.pet.server.po.ProductInfo;
import com.pet.server.po.ProductView;
import com.pet.system.constants.ATTSystem;
import com.pet.system.constants.BaseAttribute;

public class ProductAction extends BaseAction {

	private static final long serialVersionUID = 1L;
	private Integer id;
	private Integer productId;
	private ProductInfo product;
	private ProductData pd;
	private ProductView pv;
	private String productName,imgFileFileName;
	private Date beginDate;
	private Date endDate;
	private ProductService productService;
	private File imgFile;
	private File ico,image1,image2,image3;
	private String icoFileName,image1FileName,image2FileName,image3FileName;
	
	
	
	
	public ProductData getPd() {
		return pd;
	}
	public void setPd(ProductData pd) {
		this.pd = pd;
	}
	public String getProductName() {
		return productName;
	}
	public void setProductName(String productName) {
		this.productName = productName;
	}
	public Date getBeginDate() {
		return beginDate;
	}
	public void setBeginDate(Date beginDate) {
		this.beginDate = beginDate;
	}
	public Date getEndDate() {
		return endDate;
	}
	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}
	public Integer getProductId() {
		return productId;
	}
	public void setProductId(Integer productId) {
		this.productId = productId;
	}
	
	public ProductView getPv() {
		return pv;
	}
	public void setPv(ProductView pv) {
		this.pv = pv;
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public ProductInfo getProduct() {
		return product;
	}
	public void setProduct(ProductInfo product) {
		this.product = product;
	}
	public ProductService getProductService() {
		return productService;
	}
	public void setProductService(ProductService productService) {
		this.productService = productService;
	}
	
	/**
	 * 删除产品数据
	 * @return
	 */
	public String deleteProductInfo(){
		ProductInfo v = productService.getObject(id, ProductInfo.class);
		if(null!=v){
			v.setState(ATTSystem.DEV);
			productService.updateObject(v);
		}
		return SUCCESS;
	}
	
	/**
	 * 删除产品数据
	 * @return
	 */
	public String deleteProductAlima(){
		ProductData v = productService.getObject(id, ProductData.class);
		if(null!=v){
			v.setState(4);
			productService.updateObject(v);
		}
		return SUCCESS;
	}
	/**
	 * 查询淘宝商品信息
	 * @return
	 */
	public String searchProductAlima(){
		Page page = PagerFactory.createPage();
		productService.searchProductAlima(pd, page);
		setAttr(ATTPage.PAGE_LIST, page);
		
		
		//System.out.println("======================="+pd.getProductCate());
		
		
		return SUCCESS;
	}
	
	
	/**
	 * 淘宝编辑
	 * @return
	 */
	public String toProductAlima(){
		ProductData pro = productService.getObject(id,ProductData.class);
		setAttr(BaseAttribute.PRODUCT_INFO, pro);
		return SUCCESS;
	}
	
	public String suProductAlima(){
		ProductData p = productService.getObject(id,ProductData.class);
		 if(null!=pd){
		    productService.updateProductAlima(p, pd, imgFile, imgFileFileName);
		}
		
		return SUCCESS;
	}

	
	/**
	 *功能描述:查询产品信息
	 * 2013-6-25
	 * @return
	 * Administrator
	 */
	public String searchProductInfo(){
		Page page = PagerFactory.createPage();
		productService.searchProductInfo(product, page);
		setAttr(ATTPage.PAGE_LIST, page);
		return SUCCESS;
	}
	public String searchDateReport(){
		Page page = PagerFactory.createPage();
		productService.searchDateReport(productName, productId, beginDate, endDate, page);
		setAttr(ATTPage.PAGE_LIST, page);
		return SUCCESS;
	}
	public String searchAdvise(){
		Page page = PagerFactory.createPage();
		productService.searchAdvise(page);
		setAttr(ATTPage.PAGE_LIST, page);
		return SUCCESS;
	}
	
	/**
	 *功能描述:进入产品信息
	 * 2013-6-25
	 * @return
	 * Administrator
	 */
	public String toProductInfo(){
		ProductInfo product = productService.getObject(id,ProductInfo.class);
		setAttr(BaseAttribute.PRODUCT_INFO, product);
		ProductImg productImg=productService.getImg(id);
		setAttr(BaseAttribute.PRODUCT_IMG, productImg);
		return SUCCESS;
	}
	
	
	/**
	 *功能描述:添加或者编辑产品信息
	 * 2013-6-25
	 * @return
	 * Administrator
	 */
	public String suProductInfo(){
		ProductInfo p = productService.getObject(id,ProductInfo.class);
		if(null==p && null!=product){
			productService.saveProductInfo(product, imgFile, imgFileFileName,image1, image2, image3, image1FileName, image2FileName, image3FileName);
		}else if(null!=product){
		    productService.updateProductInfo(p, product, imgFile, imgFileFileName,image1, image2, image3, image1FileName, image2FileName, image3FileName);
		}
		
		return SUCCESS;
	}
	/**
	 *功能描述:
	 * 2013-6-26
	 * @return
	 * Administrator
	 */
	public String toProductView(){
		ProductInfo p = productService.getObject(productId, ProductInfo.class);
		
		if(null!=p){
			
			
			ProductView view = productService.getObject(id, ProductView.class);
			setAttr(BaseAttribute.PRODUCT_VIEW, view);
			setAttr(BaseAttribute.PRODUCT_INFO, p);
		}
		//setAttr(BaseAttribute.LIST, WanBiaoClient.queryWanbiaoCate());
		return SUCCESS;
	}
	/**
	 *功能描述:商品详情
	 * 2013-6-26
	 * @return
	 * Administrator
	 */
	public String productDetail(){
		ProductView pv = productService.getObject(id, ProductView.class);
		if(null!=pv){
			ProductInfo p = productService.getObject(pv.getProductId(), ProductInfo.class);
			ProductImg pi=new ProductImg();
			setAttr(BaseAttribute.PRODUCT_INFO, p);
			setAttr(BaseAttribute.PRODUCT_VIEW, pv);
			setAttr("vo", pi);
		}
		return SUCCESS;
	}
	
	/**
	 *功能描述:save or update product view
	 * 2013-6-26
	 * @return
	 * Administrator
	 */
	public String suProductView(){
		ProductView view = productService.getObject(id, ProductView.class);
		if(null==view&&null!=pv){
			productService.saveProductView(pv,productId);
		}else if(null!=pv){
			productService.updateProductView(view, pv);
			setProductId(view.getProductId());
		}
		return SUCCESS;
	}
	public String deleteProductView(){
		ProductView v = productService.getObject(id, ProductView.class);
		if(null!=v){
			v.setState(ATTSystem.LOGIC_FALSE);
		    productService.updateObject(v);
		}
		return SUCCESS;
	}
	
	
	/**
	 *功能描述:查询商品列表
	 * 2013-6-29
	 * @return
	 * Administrator
	 */
	public String searchProductView(){
		Page page = PagerFactory.createPage();
		productService.searchProductView(product, pv, page);
		super.setAttr(ATTPage.PAGE_LIST,page);
		return SUCCESS;
	}
	public String getImgFileFileName() {
		return imgFileFileName;
	}
	public void setImgFileFileName(String imgFileFileName) {
		this.imgFileFileName = imgFileFileName;
	}
	public File getImgFile() {
		return imgFile;
	}
	public void setImgFile(File imgFile) {
		this.imgFile = imgFile;
	}
	public File getIco() {
		return ico;
	}
	public void setIco(File ico) {
		this.ico = ico;
	}
	public File getImage1() {
		return image1;
	}
	public void setImage1(File image1) {
		this.image1 = image1;
	}
	public File getImage2() {
		return image2;
	}
	public void setImage2(File image2) {
		this.image2 = image2;
	}
	public File getImage3() {
		return image3;
	}
	public void setImage3(File image3) {
		this.image3 = image3;
	}
	public String getIcoFileName() {
		return icoFileName;
	}
	public void setIcoFileName(String icoFileName) {
		this.icoFileName = icoFileName;
	}
	public String getImage1FileName() {
		return image1FileName;
	}
	public void setImage1FileName(String image1FileName) {
		this.image1FileName = image1FileName;
	}
	public String getImage2FileName() {
		return image2FileName;
	}
	public void setImage2FileName(String image2FileName) {
		this.image2FileName = image2FileName;
	}
	public String getImage3FileName() {
		return image3FileName;
	}
	public void setImage3FileName(String image3FileName) {
		this.image3FileName = image3FileName;
	}
	
}
